package com.erpanderp.wam.adm.model.service;

import java.util.List;

import org.hibernate.FlushMode;
import org.hibernate.Query;
import org.hibernate.classic.Session;

import com.erpanderp.wam.adm.model.entity.HolidayCalendar;
import com.erpanderp.wam.util.HibernateUtil;

public class HolidayCalendarDAO {
	
	public HolidayCalendar createHolidayCalendar(HolidayCalendar holidayCalendar){
		try{
			Session session = HibernateUtil.getSessionFactory().getCurrentSession();
			session.beginTransaction();
			session.setFlushMode(FlushMode.AUTO);
			session.save(holidayCalendar);
			session.getTransaction().commit();
			return holidayCalendar;
		}catch (Exception e) {
			e.printStackTrace();
			return null;
			// TODO: handle exception
		}
	}
	public List<HolidayCalendar> getHolidays(){
		List<HolidayCalendar> holidayCalendarList = null;
		try{
			Session session = HibernateUtil.getSessionFactory().getCurrentSession();
			session.beginTransaction();
			session.setFlushMode(FlushMode.AUTO);
			String queryString = "from HolidayCalendar h";
			Query query = session.createQuery(queryString);
			holidayCalendarList = query.list();
			
			session.getTransaction().commit();
			return holidayCalendarList;
		}catch (Exception e) {
			e.printStackTrace();
			return null;
			// TODO: handle exception
		}
	}

}
